import { WidgetBaseTextSession } from './base'
import {toAny, fromAny, StringValue} from '../../proto'
export class WidgetEditorSession extends WidgetBaseTextSession {
    protected widget: HTMLInputElement
    constructor(render: HTMLElement) {
        super('Editor', render)
    }
    createWidget(): HTMLElement {
        this.widget = document.createElement('input')
        this.widget.type = 'text'
        return this.widget
    }
    onReceive(name: String, sessionId: number, futureId: number, ...argv): void {
        switch (name) {
            case 'setHint':
                return this.setHint(...argv)
            case 'getHint':
                return this.getHint(sessionId, futureId)
        }
        super.onReceive(name, sessionId, futureId, ...argv);
    }
    private setHint(...argv) {
        this.widget.placeholder = fromAny(argv[0], StringValue)
    }
    private getHint(sessionId: number, futureId: number) {
        const hint = this.widget.placeholder
        this.sendAction('onGetHint', sessionId, futureId, toAny(hint, StringValue))
    }
}